layui.define(['table', 'form', 'laypage', 'laydate', 'layer'], function (exports) {
    var $ = layui.$
        , table = layui.table
        , form = layui.form
        , laydate = layui.laydate
        , laypage = layui.laypage
        , layer = layui.layer;

    //路径
    var curWwwPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    var localhostPaht = curWwwPath.substring(0, pos);
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);

    var departmenttid = $("#departmenttid").val();

    var data=[{title: 'ID', width: 70, sort: true, fixed: 'left', type: 'numbers'},
        {field: 'title', title: '流程名', sort: true, width: 250},
        {field: 'types', title: '流程类别', sort: true,width: 120},
        {field: 'processlistString', title: '具体步骤', sort: true},
        {field: 'state', title: '流程状态', sort: true, width: 150},
        {title: '操作', toolbar: '#table-process', align: "center", width: 200, fixed: "right"}]

    var limitcount = 10;
    table.render({
        elem: '#processTable'
        , url: localhostPaht + projectName + "/rest/process/getProcessList"
        , title: "流程列表"
        , height: 'full-145'
        , page: false
        , limit: limitcount
        , text: {
            none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
        },
        toolbar: '#processOperation',
        defaultToolbar: ['filter']
        // ,skin: 'line' //表格风格
        , cols: [data],

        done: function (res, curr, count) {
            $('.layui-table-fixed-r').removeClass('layui-hide');//列固定右侧
            var curnum = $("#curnum").val();
            laypage.render({
                elem: 'laypage'
                , first: '首页'
                , last: '尾页'
                , groups: 5
                , count: count
                , curr: curnum
                , limit: limitcount
                , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                , limits: [10, 15, 20]
                , jump: function (obj, first) {
                    if (!first) {
                        curnum = obj.curr;
                        $("#curnum").val(curnum)
                        limitcount = obj.limit;
                        table.reload('processTable', { //表格的id
                            where: {
                                page: curnum,
                                limit: limitcount
                            }
                        })
                    }
                }
            })
        }
    });

    //监听工具条
    table.on('tool(processTables)', function (obj) {  //表格的lay-filter="userlists"
        var data = obj.data; //获得当前行所有数据
        // console.log(data) //当前容器的全部表单字段，名值对形式：{name: value}
        // alert(data.vip)
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的DOM对象
        // JSON.stringify(data)
        if (obj.event === 'update') {
            update(data);
        } else if (obj.event == 'info') {
            info(data);
        }
    });


    function   update(data){
        var clocess="1";
        layer.open({
            title : "修改",
            type: 2,
            content: localhostPaht +projectName+'/rest/getRoute?type=system&url=process_update',
            //是否显示右上角关闭图标，默认为1，显示
            // closeBtn:0,
            maxmin: true,
            area: ['90%', '91%'],
            //是否显示右上角关闭图标，默认为1，显示
            anim:4,
            shade:0.6,
            skin: 'layui-layer-molv',
            resize:true,
            // btn: ['启动', '取消'],
            success: function(layero, index){  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                var iframe = window['layui-layer-iframe'+index];
                //调用子页面的全局函数
                iframe.child(data.tid)
            },cancel: function(index, layero) {
                layer.close(index)
                clocess="2"
                return false;
            },
            end: function () {
                if(clocess=="2"){

                }else {
                    table.reload('processTable')
                }
                return false;
            }
        });

        // $('.layui-layer-setwin .layui-layer-max').css("display","none")
        // $('.layui-layer-setwin .layui-layer-min').css("display","none")
        // setTimeout(function(){
        //     layui.layer.tips('点击此处返回用户列表', '.layui-layer-setwin .layui-layer-close', {
        //         tips: 3
        //     });
        // },500)
        // layer.full(index);
        // window.sessionStorage.setItem("index",index);
        // //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        // $(window).on("resize",function(){
        //     layer.full(window.sessionStorage.getItem("index"));
        // })
    }


    function   info(data){
        var clocess="1";
        layer.open({
            title : "详情",
            type: 2,
            content: localhostPaht +projectName+'/rest/getRoute?type=system&url=process_detail',
            //是否显示右上角关闭图标，默认为1，显示
            // closeBtn:0,
            maxmin: true,
            area: ['90%', '91%'],
            //是否显示右上角关闭图标，默认为1，显示
            anim:4,
            shade:0.6,
            skin: 'layui-layer-molv',
            resize:true,
            // btn: ['启动', '取消'],
            success: function(layero, index){  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                var iframe = window['layui-layer-iframe'+index];
                //调用子页面的全局函数
                iframe.child(data.tid)
            },cancel: function(index, layero) {
                layer.close(index)
                clocess="2"
                return false;
            },
            end: function () {
                if(clocess=="2"){

                }else {
                    table.reload('processTable')
                }
                return false;
            }
        });

        // $('.layui-layer-setwin .layui-layer-max').css("display","none")
        // $('.layui-layer-setwin .layui-layer-min').css("display","none")
        // setTimeout(function(){
        //     layui.layer.tips('点击此处返回用户列表', '.layui-layer-setwin .layui-layer-close', {
        //         tips: 3
        //     });
        // },500)
        // layer.full(index);
        // window.sessionStorage.setItem("index",index);
        // //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        // $(window).on("resize",function(){
        //     layer.full(window.sessionStorage.getItem("index"));
        // })
    }


    exports('process', {})
});
